Skip to content

Detect the system on windows instead of reading Windows_NT - #7989

Merged
code-asher merged 1 commit into
coder:mainfrom
denusklo:windows-os-detection
Sep 8, 2026
Merged

Detect the system on windows instead of reading Windows_NT#7989
code-asher merged 1 commit into
coder:mainfrom
denusklo:windows-os-detection

Conversation

@denusklo

@denusklo denusklo commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

ci/lib.sh works out OS only when the caller has not set one:

if [[ ! ${OS-} ]]; then OS=$(os); fi

Windows predefines OS as Windows_NT in every process environment, so on a windows shell that test always finds a value, os() is never called, and OS stays Windows_NT for the whole build. Every question the build then asks about the system gets an answer it does not understand: which bin scripts to fix up, whether to build packages, what the release archive is called.

os() already handles this platform (cygwin* | mingw* answers windows), it just never gets the chance. Windows_NT is not a name this build knows, so it is not treated as one a caller chose.

Measured on a windows shell, sourcing the file three ways:

OS unset        -> windows   (was Windows_NT)
OS=Windows_NT   -> windows   (was Windows_NT)
OS=linux        -> linux     (unchanged)

so an explicit choice still wins, which is the point of the check. Nothing changes anywhere else: no other platform sets OS, so the added test is never reached off windows.

This is the "belongs in its own change" fix named in #7987; with it, that job's OS: windows env line becomes redundant rather than necessary.

ci/lib.sh works out OS only when the caller has not set one:

    if [[ ! ${OS-} ]]; then OS=$(os); fi

Windows predefines OS as Windows_NT in every process environment, so on a
windows shell that test always finds a value, os() is never called, and OS
stays Windows_NT for the whole build. Every question the build then asks about
the system gets an answer it does not understand: which bin scripts to fix up,
whether to build packages, what the release archive is called.

os() already handles this platform -- `cygwin* | mingw*` answers windows -- it
just never gets the chance. Windows_NT is not a name this build knows, so it is
not treated as one a caller chose.

Measured on a windows shell, sourcing the file three ways:

    OS unset            -> windows     (was Windows_NT)
    OS=Windows_NT       -> windows     (was Windows_NT)
    OS=linux            -> linux       (unchanged)

so an explicit choice still wins, which is the point of the check. Nothing
changes anywhere else: no other platform sets OS, so the added test is never
reached off windows.
@denusklo
denusklo requested a review from a team as a code owner September 6, 2026 03:46

@code-asher code-asher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I could see maybe an argument that if we see Windows_NT we normalize it into windows rather than run detection so that if someone runs OS=Windows_NT npm ... on say Linux, they will not end up with the potentially surprising result of OS being changed to linux, but at the same time, who is going to do that anyway.

@code-asher
code-asher merged commit 9d72dce into coder:main Sep 8, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants